const { assert } = require('../../../lib/tools')
const { toPasic, toCamel, getProperty } = require('../../libs/tools')

module.exports = function ({ base: { entryName, model, object, entryLabel,primaryKey }, fields }, globeConfig) {
    const backendConfig = getProperty(globeConfig, g=>g.globe.dist.backend)
    assert(backendConfig,`backend config is null!`)
    const {basePackage, entryPackage, controllerPackage,dir, servicePackage, mapperPackage, serviceImplPackage} = backendConfig
    const result =  {
        entryClassName: toPasic(entryName)
        , entryComment: entryLabel
        , controllerName: `${toPasic(entryName)}Controller`
        , serviceName: `I${toPasic(entryName)}Service`
        , serviceImplName: `${toPasic(entryName)}ServiceImpl`
        , serviceFieldName: `${toCamel(entryName)}Service`
        , mapperName: `${toPasic(entryName)}Mapper`
        , mapperFieldName: `${toCamel(entryName)}Mapper`
        , model: model
        , object: object
        , primaryKey
        , primaryProperty: toCamel(primaryKey)
    }

    result.entryPackage = [basePackage, entryPackage].join('\.')
    result.controllerPackage = [basePackage, controllerPackage].join('\.')
    result.servicePackage = [basePackage, servicePackage].join('\.')
    result.mapperPackage = [basePackage, mapperPackage].join('\.')
    result.serviceImplPackage = [basePackage, serviceImplPackage].join('\.')
    result.distPath = dir
    return result
}